
#include "IDeskTopShare.h"
#include <string>
#include "GetScreen.h"
#include "Jpeg2RgbScreen.h"
#include "DeskTopShare.h"

//////////////////////////////////////////////////////////////////.
BOOL APIENTRY DllMain( HMODULE hModule,
					  DWORD  ul_reason_for_call,
					  LPVOID lpReserved
					  )
{
	return TRUE;
}

////////////////////////////////DeskTopShare/////////////////////////
DeskTopShare::DeskTopShare(void)
{

}
DeskTopShare::~DeskTopShare(void)
{

}
void DeskTopShare::start(ScreenHeader screenHeader,INCOMMINGDATA callback)
{
	while (TRUE)
	{			
		LPSTR lpData = NULL;
		lpImage.Init(screenHeader.rcArea,screenHeader.nArea);
		lpData = (LPSTR)lpImage.GetScreeenData(screenHeader);
		callback(screenHeader,(char*)lpData,screenHeader.dwFileSize);
		if (lpData){
			GlobalFree(lpData);
		}
		/**sleep a moment*/
		Sleep(screenHeader.nDelay);
		//break;
	}
}
DeskTopClient::DeskTopClient():
m_Jpeg2RgbScreen(NULL)
{
	/**init Jpeg2RgbScreen*/
	 m_Jpeg2RgbScreen = new Jpeg2RgbScreen;
}

DeskTopClient::~DeskTopClient(void)
{
	/**free Jpeg2RgbScreen*/
	if(m_Jpeg2RgbScreen){
		delete m_Jpeg2RgbScreen;
		m_Jpeg2RgbScreen= NULL;
	}

}
void DeskTopClient::init(HWND hWnd)
{
	m_hWnd = hWnd;
	m_Jpeg2RgbScreen->Init(hWnd);
}
void DeskTopClient::Set_BackGroud_Image(ScreenHeader h,char* img,int size)
{
	if(!img) return;
	std::string data = std::string(img,size);
	if(!m_Jpeg2RgbScreen) return;
	/**set screen data to Jpeg2RgbScreen*/
	m_Jpeg2RgbScreen->SetScreenData(h,(BYTE *)data.c_str());
	/**draw the image on the window*/
	m_Jpeg2RgbScreen->Set_BackGroud_Image();
}
///////////////////////////////////////////////////////////////.
extern "C"__declspec(dllexport) IDeskTopShare * createIDeskTopShare()
{
	DeskTopShare * p = new DeskTopShare;
	if(p){
		return p;
	}
	return NULL;
}
extern "C"__declspec(dllexport) void destroyIDeskTopShare(IDeskTopShare * deskTop)
{
	if(deskTop) delete deskTop;

}
extern "C"__declspec(dllexport) IDeskTopClient * createDeskTopClient(HWND hWnd)
{
	DeskTopClient * p = new DeskTopClient();
	if(p){
		p->init(hWnd);
		return p;
	}
	return NULL;
}
extern "C"__declspec(dllexport) void destroyDeskTopClient(IDeskTopClient * c)
{
   if(c) delete c;
}